package cum.printer.text;

import cum.printer.Paper;

public class TextPaper implements Paper {
    private int charPerLine = 16;
    private int linePerPage = 5;
    private String content = "";
    private int posX = 0;
    private int posY = 0;
    private int posP = 1;

    public TextPaper() {
    }

    public String getContent() {
        String ret = this.content;
        if (this.posX != 0 || this.posY != 0) {
            int count = this.linePerPage - this.posY;

            for(int i = 0; i < count; ++i) {
                ret = ret + "\r\n";
            }

            ret = ret + "==第" + this.posP + "页 ==";
        }

        return ret;
    }

    public void putInChar(char c) {
        this.content = this.content + c;
        ++this.posX;
        if (this.posX == this.charPerLine) {
            this.content = this.content + "\r\n";
            this.posX = 0;
            ++this.posX;
        }

        if (this.posY == this.linePerPage) {
            this.content = this.content + "==第" + this.posP + "页 ==";
            this.content = this.content + "\r\n\r\n";
            this.posY = 0;
            ++this.posP;
        }

    }

    public void setCharPerLine(int charPerLine) {
        this.charPerLine = charPerLine;
    }

    public void setLinePerPage(int linePerPage) {
        this.linePerPage = linePerPage;
    }
}
